import {
  strokeColor,
  labelColor,
  lineWidth,
  radius,
  fontSize,
  fontWeight,
  lineHeight,
  setState,
  addControlPoint
} from './common';
G6.registerNode('door-node', {
  draw(cfg, group) {
    let { node_height, node_width, node_label } = cfg.custom_info || {};
    node_height = Number(node_height);
    node_width = Number(node_width);
    const rect = group.addShape('rect', {
      name: 'door',
      attrs: {
        fill: strokeColor,
        stroke: strokeColor,
        height: node_height,
        width: node_width,
        lineWidth: lineWidth,
        radius: radius
      }
    });

    // 文字区域
    const topGroup = group.addGroup({
      name: 'label-group'
    });

    topGroup.addShape('text', {
      attrs: {
        text: node_label || '',
        x: 0.5 * node_width,
        y: 0.5 * node_height,
        fontSize: fontSize,
        textAlign: 'center',
        textBaseline: 'middle',
        fontWeight: fontWeight,
        lineHeight: lineHeight,
        fill: labelColor
      },
      name: 'top-text',
      capture: true,
      draggable: true
    });
    addControlPoint(group, cfg);
    return rect;
  },
  setState(name, value, item) {
    setState({ name, value, item, node_name: 'door' });
  }
});
